var express = require('express');
var router = express.Router();
var { json_p } = require('../util.js')
var { post_sql_query, post_sql_add, post_sql_delete, post_sql_update, post_url } = require('../wechat/api.js')

router.get('/user_list', async (req, res) => {
    //微信文档 https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseQuery.html
    /**
     * 方法一
     */
    let resData = await post_url('databasequery', {
        query: `db.collection('user').get()`
    })
    /**
     * 方法二
     */
    let resData1 = await post_sql_query({
        query: `db.collection('user').get()`
    })
    /**
     * json_p  方法 json字符串转json对象
     */
    res.json({
        code: resData.errcode,
        data: json_p(resData.data),
        data1: json_p(resData1.data)
    })
})

module.exports = router;
